//
//  HJCategroyHeader.m
//  Sneakers
//
//  Created by 胡光健 on 2017/9/21.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "HJCategroyHeader.h"
@interface HJCategroyHeader()
@property(nonatomic,strong)NSString * brand_id;
@property (weak, nonatomic) IBOutlet UIScrollView *titleScroll;
@property (weak, nonatomic) IBOutlet UIButton *btn;
@end

@implementation HJCategroyHeader

-(void)awakeFromNib {
    [super awakeFromNib];
    self.layer.shadowOpacity = 0.5;
    self.layer.shadowRadius = 1;
    self.layer.shadowOffset = CGSizeZero;
    self.layer.shadowColor = [UIColor grayColor].CGColor;
    self.btn.titleLabel.font = HJFontSize(mScreenWidth/414 *15);
    self.leftLabel.font = HJFontSize(mScreenWidth/414 *15);
    self.rightLabel.font = HJFontSize(mScreenWidth/414 *15);
}

-(instancetype)init {
    if (self = [super init]) {
        self =[[NSBundle mainBundle]loadNibNamed:@"HJCategroyHeader" owner:self options:nil].firstObject;
    }
    return self;
}

-(void)setHeaderArr:(NSArray *)headerArr {
    _headerArr = headerArr;
    NSMutableArray *ar = [NSMutableArray array];
    NSMutableArray * showArr = [NSMutableArray array];
    for (int i =0; i<headerArr.count; i++) {
        NSString * title;
        if (i==0) {
            title = @"全部";
        }else {
            title = headerArr[i-1][@"brand_name"];
        }
        NSNumber * num = @1;
        [ar addObject:title];
        [showArr addObject:num];
    }
    _headerBtns = [[TZButtonsHeaderView alloc] init];
    _headerBtns.frame = CGRectMake(0, 0, self.titleView.width, self.titleView.height);
    _headerBtns.notCalcuLateTitleWidth = NO;
    _headerBtns.shouldSelect = YES;
    _headerBtns.titles = ar;
    _headerBtns.btnWidth = 90;
    _headerBtns.showSpots = showArr;
    _headerBtns.selectBtnIndex = 0;
    _headerBtns.changeFontWhenSelected = YES;
    _headerBtns.contentSize = CGSizeMake(headerArr.count * 90 , 40);
    [_headerBtns setDidClickButtonWithIndex:^(TZBaseButton *btn, NSInteger index) {
        NSMutableDictionary * dic = [NSMutableDictionary dictionary];
        dic[@"index"] = @(index);
        if (index==0) {
            dic[@"brand_id"] = @"";
        }else {
            dic[@"brand_id"] = headerArr[index-1][@"brand_id"];
        }
        [[NSNotificationCenter defaultCenter]postNotificationName:@"buttonWithIndex" object:nil userInfo:dic];

//        if (index>1 &&index<showArr.count-2) {
//            weakSelf.headerBtns.contentOffset = CGPointMake(weakSelf.headerBtns.btnWidth *(index -2) +weakSelf.headerBtns.btnWidth/4, 0);
//        }else if (index < 2) {
//            weakSelf.headerBtns.contentOffset = CGPointMake(0, 0);
//        }else {
//            weakSelf.headerBtns.contentOffset = CGPointMake(weakSelf.headerBtns.btnWidth *(showArr.count-2.5), 0);
//        }
    }];
    [self.titleView addSubview:_headerBtns];
}

//综合按钮201
- (IBAction)synthesize:(UIButton *)sender {
    [[NSNotificationCenter defaultCenter]postNotificationName:@"synthesizeBtnPush" object:nil];
    
}
//筛选202
- (IBAction)screeningList:(UIButton *)sender {
    [[NSNotificationCenter defaultCenter]postNotificationName:@"screeningListBtnPush" object:nil];
}

@end
